class Solution(object):
    def maxLength(self, ribbons, k):
        if sum(ribbons) < k:
            return 0
        left = 1
        right = max(ribbons)
        def search(val):
            ans = 0
            for num in ribbons:
                ans += num // val
            return ans >= k

        while left < right:
            mid = (left + right + 1) // 2
            if search(mid):
                left = mid
            else:
                right = mid - 1
        return left